package com.yorge.service.impl;

import com.yorge.entities.Payment;
import com.yorge.dao.PaymentDao;
import com.yorge.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Slf4j
@Service
public class PaymentServiceImpl implements PaymentService {
    @Resource
    private PaymentDao paymentDao;

    @Override
    public Payment getPayment(Long id) {
        return paymentDao.getPayment(id);
    }

    @Override
    public int addPayment(Payment payment) {
        return paymentDao.create(payment);
    }

    @Override
    @Transactional(rollbackFor = Exception.class, isolation = Isolation.DEFAULT)
    public void testTransactional() throws Exception {
        paymentDao.update("4111", "4");

        try {
            int i = 1 / 0;
        } catch (Exception e) {
            throw new Exception("adsfadf");
        }
//        paymentDao.update("2313", "4");
    }
}
